<?php

namespace App\Models;

/**
 * App\Models\Integral
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $username 用户名
 * @property int $mumber 积分数量
 * @property int $type 状态1加分2减分
 * @property string $note 积分备注
 * @property \Illuminate\Support\Carbon|null $created_at
 * @method static \Illuminate\Database\Eloquent\Builder|Integral newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Integral newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Integral query()
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereMumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereNote($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Integral whereUsername($value)
 * @mixin \Eloquent
 */
class Integral extends Base
{
    protected $table = 'integrals';

    protected $fillable = [
        'id','user_id','mumber','type','note','created_at',
    ];

    public $timestamps = false;//关闭自动维护

    protected $dates = ['created_at'];

    /**
     * 获取列表
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @return mixed
     */
    protected function getList($params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['uid']) && $params['uid']) {
                    $query ->where('user_id',$params['uid']);
                }
            })->orderBy('id', 'desc')
            ->paginate(config('app.limit'));
        return $lists;
    }

}
